package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        //文件流:(字节流,低级流):将字节写到文件中
        FileOutputStream fos = new FileOutputStream("pw.txt");
        //转换流(字符流,高级流):1.负责衔接字符流与字节流 2.将写出的字符转换为字节
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //缓冲字符流(字符流,高级流):块文本数据加速(内部缓冲区默认8192个char)
        BufferedWriter bw = new BufferedWriter(osw);
        //PrintWriter(字符流,高级流):1.按行写出
        PrintWriter pw = new PrintWriter(bw,true);//true:开启自动刷新

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入内容:");
        while (true){
            String line = sc.nextLine();
            if ("exit".equals(line)){
                break;
            }
            pw.println(line); //按行写入
            //pw.flush();
        }
        pw.close();















    }
}
